<?php
//
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'get_detail';
if($_RQ['op']=='get_detail'){
	$id=intval($_RQ['id']);
	//来自其他插件的购物
	$this->session('fromplugin_name',$_RQ['plugin_name']);
	$this->session('frompid',intval($_RQ['frompid']));
	if(!$id){
		exi('没有商品ID','error','jy_xunichong/index/');
	}
	$goods=pdo_get('jy_xunichong_goods',array('id'=>$id,'status'=>1,'uniacid'=>$_SESSION['uniacid']));
	if(!$goods){
		exi('选择的商品不存在或已下架，请重新选择！','error','/index/');
	}
	$_SESSION['goodsid'] = $goods['id'];
	$goods['image']=$goods['image']?tomedia($goods['image']):'';
	$goods['video']=$goods['video']?tomedia($goods['video']):'';
	$goods['images']=json_decode($goods['images'],true);
	foreach($goods['images'] as &$image){
		$image=tomedia($image);
	}
	if(count($goods['images'])<1){
		$goods['images'][]=tomedia($goods['image']);
	}
	$return['url']=custom_url('jy_xunichong/goods.detail//id='.$id,true);
	$goods['canbuy'] = $goods['status'] == 1 && $goods['total'] > 0 ?1:0;
	$goods['unit'] = ((empty($goods['unit']) ? '件' : $goods['unit']));
	$goods['desc'] = cfc('tools')->substr($goods['desc'],0,48);
	$goods['typetitle']=$this->gift_type[$goods['type']];
	//判断nobuy状态：
	$goods['nobuytitle']='商品已售罄';	
	$post['num'] = 1;
	$post['goodsid'] = $_SESSION['goodsid'];
	$return['post']=$post;
	$goods['url']=custom_url('jy_xunichong/goods.detail//id='.$goods['id'],true);
	$return['images']=$goods['images'];
	//现在时间时间戳
	$return['time']=time();
	$date_time=date('Y-m-d H:i:s',$return['time']);
	$return['sharedata']=array(
		'title'=>$goods['title'],
		'desc'=>$goods['desc']?$goods['desc']:$goods['title'],
		'link'=>custom_url('jy_xunichong/goods.detail//id='.$id.'&fromuser='.$_SESSION['uid'].'&current_plugin='.$_SESSION['current_plugin'],true),
		'imgUrl'=>tomedia($goods['image'])
	);
	$return['goods']=$goods;	
	set_html('title',$goods['title']?:'商品详情');
	exi($return);
}
if($_RQ['op']=='check_buy'){
	$goodsid=$_RQ['goodsid']?intval($_RQ['goodsid']):$_SESSION['goodsid'];
	exi('','','jy_xunichong/order.create//goodsid='.$goodsid.'&num='.$_RQ['num']);
}